package zhtt;

import org.apache.ibatis.session.SqlSession;
import org.junit.Test;
import zhtt.demo02.Vehicle;
import zhtt.demo02.VehicleDict;

/**
 * Created by zhtt on 2017/4/30.
 */
public class VehicleTest {

    @Test
    public void insert(){
        SqlSession sqlSession= SessionFactoryUtil.getSqlSessionIntance();
        try{
            Vehicle vehicle=new Vehicle(2017,"china","red",1);
            int r=sqlSession.insert("zhtt.demo02.Vehicle.insert",vehicle);
            System.out.println(r);
            Vehicle vehicle2=new Vehicle(2007,"china","blue",2);
            int r2=sqlSession.insert("zhtt.demo02.Vehicle.insert",vehicle2);
            System.out.println(r2);
            sqlSession.commit();
        }catch (Exception e){
            e.printStackTrace();
            sqlSession.rollback();
        }finally {
            if(sqlSession!=null)
                sqlSession.close();
        }
    }
}
